﻿using Mrc.Common;
using Mrc.Domain.Entitity;
using Mrc.SqlSurging;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Mrc.Domain.Module.ConfigCenter
{
    public class ConfigMasterService:IConfigMasterService
    {
        public SqlSugarClient Db;
        public ConfigMasterService()
        {
            Db = new SqlSugarClient(ConnectionConfigManager.Get("admin"));
        }
        public ConfigMasterService(ISqlSurgarClientService  sqlSurgarClientService)
        {
            Db = sqlSurgarClientService.Client("admin");
        }

        public Task Add(ConfigMaster model)
        {
            Verify(model);
            Db.Insertable(model).ExecuteCommand();          
            return Task.FromResult(true);
        }

        public Task SetUse(long Id, bool isUse)
        {
            
            return Task.FromResult(true);
        }
        public Task Delete(long Id)
        {

            return Task.FromResult(true);
        }

        public void Verify(ConfigMaster model)
        {
            if (string.IsNullOrWhiteSpace(model.ItemName))
            {
                throw new MrcException("项目名称不能为空");
            }
            if (model.Env < 0)
            {
                throw new MrcException("环境错误");
            }
            if (string.IsNullOrWhiteSpace(model.Host))
            {
                throw new MrcException("输入主节点信息");
            }

        }
    }

}
